package controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class CheckCode
 */
@WebServlet("/CheckCode")
public class CheckCode1 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public CheckCode1() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//这里接受ajax提交的请求
		//从请求中获得用户输入的验证码
		String userCode = request.getParameter("code");
		//从session中获得生成时保存下来的验证码
		String sessionCode = (String) request.getSession().getAttribute("code");
		//比较两个验证码，返回比较结果
		if(userCode.equals(sessionCode)) {
			response.getWriter().append("ok");
		} else {
			response.getWriter().append("fail");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
